package com.wyzz.hr.action;

import java.util.*;
import org.hibernate.criterion.DetachedCriteria;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.bo.IAttdoriginaldataBO;
import com.wyzz.hr.bo.IEmployeeBo;
import com.wyzz.hr.bo.IIodefBo;
import com.wyzz.hr.bo.impl.ExaminDateUtil;
import com.wyzz.hr.pojo.Attdoriginaldata;
import com.wyzz.hr.pojo.Employee;
import com.wyzz.hr.pojo.Iodef;
import com.wyzz.hr.spring.SpringBeanFactory;
import com.wyzz.hr.util.DatabaseSysConfigManager;
import com.wyzz.hr.util.DateUtil;
import com.wyzz.hr.util.Pager;

public class OriginalDataImportShowAction extends BaseAction {

	public OriginalDataImportShowAction() {
		searchBean = null;
		iodefId = "IExamBasic";
		iodef = null;
		page = new Pager();
		locationList = null;
		machineList = null;
		empIdStr = null;
		empNo = new String[0];
	}

	public String execute() throws Exception {
		if (searchBean == null) {
			searchBean = new Attdoriginaldata();
			searchBean.setBeginHour(0.0F);
			searchBean.setEndHour(24F);
			String config = DatabaseSysConfigManager.getInstance().getProperty(
					"sys.examin.month.sum");
			Date dateArr[] = ExaminDateUtil.getDateArray(DateUtil
					.convDateToYM(new Date()), config);
			searchBean.setStartDate(dateArr[0]);
			searchBean.setEndDate(dateArr[1]);
		}
		if (operate != null && "delete".equals(operate)) {
			deleteOneOriginalData();
			operate = null;
		}
		IAttdoriginaldataBO originaldataBo = (IAttdoriginaldataBO) SpringBeanFactory
				.getBean("attdoriginaldataBO");
		DetachedCriteria dc = DetachedCriteria.forClass(Attdoriginaldata.class);
		if ("SUB".equals(super.authorityCondition))
			addSubDC(dc, "emp", 4);
		originalDataList = originaldataBo.searchOriginalDataList(dc, page,
				searchBean);
		getDrillDownList();
		return "success";
	}

	private void getDrillDownList() {
		locationList = getDrillDown("Location", new String[0]);
		machineList = getDrillDown("AttdMachine", new String[0]);
		IIodefBo iodefBo = (IIodefBo) SpringBeanFactory.getBean("iodefbo");
		iodef = iodefBo.searchIodefByName(iodefId);
		IEmployeeBo empBo = (IEmployeeBo) getBean("empBo");
		empList = empBo.getEmpsNeedCard(Integer.valueOf(1), new String[0]);
	}

	public String deleteOriginalData() throws Exception {
		IAttdoriginaldataBO originaldataBo = (IAttdoriginaldataBO) SpringBeanFactory
				.getBean("attdoriginaldataBO");
		originaldataBo.deleteDataInDateDomain(searchBean.getStartDate(),
				searchBean.getEndDate());
		addSuccessInfo("\u8003\u52E4\u673A\u5237\u5361\u6570\u636E\u6E05\u7406\u6210\u529F\u3002");
		return "success";
	}

	public String deleteOneOriginalData() throws Exception {
		IAttdoriginaldataBO originaldataBo = (IAttdoriginaldataBO) SpringBeanFactory
				.getBean("attdoriginaldataBO");
		originaldataBo.deleteAttdoriginaldata(aodIds);
		addSuccessInfo("\u8003\u52E4\u673A\u5237\u5361\u6570\u636E\u5220\u9664\u6210\u529F\u3002");
		return "success";
	}

	public Map changeNightShift(String aodIds, Integer type) throws Exception {
		IAttdoriginaldataBO originaldataBo = (IAttdoriginaldataBO) SpringBeanFactory
				.getBean("attdoriginaldataBO");
		Map result = originaldataBo.changeNightShift(aodIds, type);
		return result;
	}

	public Integer checkDateAndCardTime(Date aodDate, Date aodCardTime) {
		String dateStr = DateUtil.formatDate(aodDate);
		String cardStr = DateUtil.formatDate(aodCardTime);
		if (dateStr.equals(cardStr))
			return Integer.valueOf(0);
		else
			return Integer.valueOf(1);
	}

	public List getOriginalDataList() {
		return originalDataList;
	}

	public void setOriginalDataList(List originalDataList) {
		this.originalDataList = originalDataList;
	}

	public String getIodefId() {
		return iodefId;
	}

	public void setIodefId(String iodefId) {
		this.iodefId = iodefId;
	}

	public Iodef getIodef() {
		return iodef;
	}

	public void setIodef(Iodef iodef) {
		this.iodef = iodef;
	}

	public Pager getPage() {
		return page;
	}

	public void setPage(Pager page) {
		this.page = page;
	}

	public Employee getAttdEmp() {
		return attdEmp;
	}

	public void setAttdEmp(Employee attdEmp) {
		this.attdEmp = attdEmp;
	}

	public List getEmpList() {
		return empList;
	}

	public void setEmpList(List empList) {
		this.empList = empList;
	}

	public List getLocationList() {
		return locationList;
	}

	public void setLocationList(List locationList) {
		this.locationList = locationList;
	}

	public List getMachineList() {
		return machineList;
	}

	public void setMachineList(List machineList) {
		this.machineList = machineList;
	}

	public String getAodTtdMachineNo() {
		return aodTtdMachineNo;
	}

	public void setAodTtdMachineNo(String aodTtdMachineNo) {
		this.aodTtdMachineNo = aodTtdMachineNo;
	}

	public Date getAttdDate() {
		return attdDate;
	}

	public void setAttdDate(Date attdDate) {
		this.attdDate = attdDate;
	}

	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public String[] getEmpNo() {
		return empNo;
	}

	public void setEmpNo(String empNo[]) {
		this.empNo = empNo;
	}

	public Date getAttdCardTime() {
		return attdCardTime;
	}

	public void setAttdCardTime(Date attdCardTime) {
		this.attdCardTime = attdCardTime;
	}

	public String getEmpIdStr() {
		return empIdStr;
	}

	public void setEmpIdStr(String empIdStr) {
		this.empIdStr = empIdStr;
	}

	public String getOperate() {
		return operate;
	}

	public void setOperate(String operate) {
		this.operate = operate;
	}

	public Attdoriginaldata getSearchBean() {
		return searchBean;
	}

	public void setSearchBean(Attdoriginaldata searchBean) {
		this.searchBean = searchBean;
	}

	public String getAodIds() {
		return aodIds;
	}

	public void setAodIds(String aodIds) {
		this.aodIds = aodIds;
	}

	private static final long serialVersionUID = 0xdfc27e7b7714a9eeL;
	private Attdoriginaldata searchBean;
	private String iodefId;
	private Iodef iodef;
	private Pager page;
	private List originalDataList;
	private String aodIds;
	private Employee attdEmp;
	private List empList;
	private List locationList;
	private List machineList;
	private String empIdStr;
	private String empNo[];
	private Date attdDate;
	private Date attdCardTime;
	private String aodTtdMachineNo;
	private String memo;
	private String operate;
}
